﻿using MediatR;
using Traceability.App.Api.Application.Command.Detail.DeepProcessing;
using Traceability.App.ErrorCount;
using Traceability.App.InfrasIntructure;
using Traceability.App.Model.DeepProcessing;

namespace Traceability.App.Api.Application.Handler.Detail.DeepProcessing
{
    public class GetVendorHandler : IRequestHandler<GetVendorCommand, ApiResult<DeepVendorModel>>
    {
        IBaseRepository<DeepVendorModel> deepRepo;

        public GetVendorHandler(IBaseRepository<DeepVendorModel> deepRepo)
        {
            this.deepRepo = deepRepo;
        }

        public Task<ApiResult<DeepVendorModel>> Handle(GetVendorCommand request, CancellationToken cancellationToken)
        {
            ApiResult<DeepVendorModel> res=new ApiResult<DeepVendorModel> ();
            var ssss = deepRepo.GetAll().Where(c => c.Batch == request.Batch && c.VendorType==request.VendorType).OrderByDescending(c => c.Id).FirstOrDefault();
            if (ssss == null)
            {
                res.Msg = "错误";
                res.Code = ApiEnum.Fail;
                return Task.FromResult(res);
            }
            res.Msg = "成功";
            res.Code = ApiEnum.Success;
            res.Datas = ssss;
            return Task.FromResult(res);
        }
    }
}
